import nci60.data.protein.uniprot.UniprotGOClass
import nci60.data.protein.uniprot.UniprotGOEvidence

def config = new ConfigSlurper().parse(new File('scripts/2_upload_proteins_uniprot.conf').toURL())

//sets the Services in the Upload class, to make them available
def uploadService = ctx.getBean("uploadService")

println 'setting up go classes'

def goclasses = [P:'biological Process',
                 F:'molecular Function',
                 C:'cellular Component',
                 '?':'unknown']

goclasses.each{k,v->
    def goclass = UniprotGOClass.findByLetter(k)
    if(goclass==null){
        goclass = new UniprotGOClass(letter:k, name:v)
    }else{
        goclass.name = v
    }
    if (!goclass.save(flush:true)) {
        goclass.errors.each {println it}
    }
}

println 'setting up go evidence classes'

def goevidences = [IDA:'inferred from direct assay',
                    IMP:'inferred from mutant phenotype',
                    IGI:'inferred from genetic interaction',
                    IPI:'inferred from physical interaction',
                    IEP:'inferred from expression pattern',
                    TAS:'traceable author statement',
                    NAS:'non-traceable author statement',
                    IC:'inferred by curator',
                    ISS:'inferred from sequence or structural similarity',
                    IEA:'unknown',
                    EXP:'unknown',
                    IBA:'unknown']

goevidences.each{k,v->
    def goevidence = UniprotGOEvidence.findByLetters(k)
    if(goevidence==null){
        goevidence = new UniprotGOEvidence(letters:k, name:v)
    }else{
        goevidence.name = v
    }
    if (!goevidence.save(flush:true)) {
        goevidence.errors.each {println it}
    }
}

uploadService.uploadUniprot(new File(config.uniprotFile), config.outputFolder, config.upload.toBoolean())